package demo2;

//继承：对共性进行抽取，把抽取出来的共性放到父类当中；好处：达到了代码的复用
//父类/基类/超类
class Animal {
    public String name;
    public int age;

    public Animal() {
        System.out.println("Animal不带参数的构造方法！");
    }
    public Animal(String name, int age) {
        this.name = name;
        this.age = age;
    }
    public void eat() {
        System.out.println(this.name + "正在吃");
    }
}

class Dog extends demo2.Animal {
    String color;
//    public Dog() {
//        super("元宝",4);
//    }

    public Dog() {
        System.out.println("Dog不带参数的构造方法！");
    }
    public Dog(String name,int age,String color) {
        super(name,age);
        this.color = color;
    }
    public Dog(String name, int age) {
        super(name,age);
    }

    public void bark() {

        System.out.println(this.name + "汪汪汪！");
    }

    public void eat() {
        System.out.println(this.name + "正在吃狗粮");
    }
}

//子类/派生类
class Cat extends demo2.Animal {
    public Cat() {
        super("lixi",2);
        System.out.println("不带参数的构造方法Cat");
    }

    public Cat(String name ,int age) {
        super(name,age);
    }

    public void miao() {
        System.out.println(this.name + "正在喵喵");
    }

    public void eat() {
        System.out.println(this.name + "正在吃猫粮");
    }
}

public class Test2 {
    public static void main(String[] args) {
        Dog dog = new Dog("元宝",19);
        dog.eat();
        Cat cat = new Cat();
        cat.eat();
    }
}
